package edu.nf.ch04;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author wangl
 * @date 2025/4/28
 * 自定义后置处理器（BeanPostProcessor）
 * 后置处理器可以在spring容器装配完bean（包括依赖注入）之后，
 * 在执行bean的初始化方法前后执行。
 * 注意：后置处理器是针对所有的Bean
 *
 */
public class ServicePostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("执行postProcessBeforeInitialization方法");
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("执行postProcessAfterInitialization方法");
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }
}